<template>
  <div class="search-root">
    <el-button style="margin-bottom: 24px" type="primary">
      导出
    </el-button>
    <el-table
      :data="tableData"
      stripe
      style="width: 100%"
      :loading="loading"
    >
      <el-table-column
        prop="phone"
        label="手机号"
      />
      <el-table-column
        prop="name"
        label="姓名"
      />
      <el-table-column
        prop="total_money"
        label="到账总额"
      />
      <el-table-column
        prop="number"
        label="期数"
      />
      <el-table-column
        prop="instalment"
        label="每期金额"
      />
      <el-table-column
        prop="pay_number"
        label="已还期数"
      />
      <el-table-column
        prop="overdue_number"
        label="逾期期数"
      />
    </el-table>
    <el-pagination
      background
      :current-page.sync="page_index"
      :page-size="page_size"
      layout="sizes,prev, pager, next"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      page_index: 1,
      page_size: 10,
      total: 0,
      tableData: [],
      loading: false
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    handleSizeChange(value) {
      this.page_size = value
      this.getData()
    },
    handleCurrentChange() {
      this.getData()
    },
    getData() {
      this.loading = true
      axios.get('/user', {
        params: {
          page_index: this.page_index,
          page_size: this.page_size
        }
      }).then(res => {
        const { data, page_index, page_size, total } = res.data
        this.tableData = data
        this.page_index = page_index
        this.page_size = page_size
        this.total = total
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>
<style scoped>
    .search-root {
        padding: 24px;
    }
  .el-table {
    margin-bottom: 24px;
  }
</style>
